package com.jt.tenant.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpServer;

import org.json.JSONObject;

/**
 * Created by Administrator on 2016/4/5.
 */
@HttpServer("http://api.map.baidu.com/geocoder/v2/")
public class GetCityCode extends JTAsyGet<GetCityCode.Info>{

    public String ak = "uXd1sQo9pvTXTOUeSmoAjy6b";

    public String location ;

    public String output = "json";

    public String coordtype = "bd09ll";

    public GetCityCode(String location,AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

        this.location = location;

    }

    @Override
    protected Info parser(JSONObject object) {

        if(object.optString("status").equals("0")){

            Info info = new Info();

            JSONObject jsonObject = object.optJSONObject("result");

            JSONObject jsonObject1 = jsonObject.optJSONObject("location");

            info.lng = jsonObject1.optString("lng");

            info.lat = jsonObject1.optString("lat");

            JSONObject obj = jsonObject.optJSONObject("addressComponent");

            info.city = obj.optString("city");

            info.cityCode = jsonObject.optString("cityCode");

            return info;

        }


            return null;


    }

    public static class Info{

        public String lng,lat,city,cityCode;

    }
}
